package com.wangchao.administrator.zenmechi.ui.stepactivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.base.BaseActivity;
import com.wangchao.administrator.zenmechi.bean.stepbean.StepResultBean;
import com.wangchao.administrator.zenmechi.customview.MyListView;
import com.wangchao.administrator.zenmechi.image.ImageHepler;
import com.wangchao.administrator.zenmechi.ui.fragment.cookeractivity.CookerActivity;
import com.wangchao.administrator.zenmechi.ui.mainactivity.MainActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17.
 */
public class StepActivity extends BaseActivity implements StepActivityContract.View, View.OnClickListener {


    @BindView(R.id.tv_step_title)
    TextView tvStepTitle;
    @BindView(R.id.image_back)
    ImageView imageBack;
    @BindView(R.id.header_layout)
    RelativeLayout headerLayout;
    @BindView(R.id.tv_step_name)
    TextView tvStepName;
    @BindView(R.id.tv_step_short_intro)
    TextView tvStepShortIntro;
    @BindView(R.id.lv_materials)
    MyListView lvMaterials;
    @BindView(R.id.lv_ingredients)
    MyListView lvIngredients;
    @BindView(R.id.wv_step)
    WebView wvStep;
    @BindView(R.id.tv_hire)
    TextView tvHire;
    @BindView(R.id.tv_basket)
    TextView tvBasket;
    @BindView(R.id.foot_layout)
    LinearLayout footLayout;
    @BindView(R.id.image_cover)
    ImageView imageCover;
    private String itemId;
    private StepActivityPresenter presenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        initData();
        presenter = new StepActivityPresenter(this);
        presenter.getStep(this);
    }

    @Override
    public void initViews() {

        tvBasket.setOnClickListener(this);
    }

    @Override
    public void initData() {

        Intent intent = getIntent();
        itemId = intent.getStringExtra("id");
        //Log.i("tag","----------"+itemId);
        imageBack.setOnClickListener(this);
        tvHire.setOnClickListener(this);
        tvBasket.setOnClickListener(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_step;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.image_back:
                StepActivity.this.finish();
                break;
            case R.id.tv_hire:
                startActivity(new Intent(StepActivity.this, CookerActivity.class));
                break;
            case R.id.tv_basket:
                EventBus.getDefault().post("basket");
                startActivity(new Intent(StepActivity.this, MainActivity.class));
                break;
        }
    }

    @Override
    public String getItemId() {
        return itemId;
    }

    @Override
    public void initScrollView(StepResultBean bean) {
        ImageHepler.showImage(StepActivity.this, bean.getDetail_pic(),imageCover);
        tvStepTitle.setText(bean.getName());
        tvStepName.setText(bean.getName());
        tvStepShortIntro.setText(bean.getShort_intro());
        wvStep.getSettings().setJavaScriptEnabled(true);
        wvStep.loadUrl(bean.getDetail_url());
        wvStep.setWebViewClient(new WebViewClient());
    }

    @Override
    public void initMaterials(MyAdapterForMaterial adapter) {
        lvMaterials.setAdapter(adapter);
    }

    @Override
    public void initIngredients(MyAdapterForingredients adapter) {
        lvIngredients.setAdapter(adapter);
    }

}
